package com.wl.config;

import javax.servlet.Filter;

import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.wl.filter.MyFilter;
import com.wl.filter.SessionFilter;

@Configuration
public class FilterConfiguration {
	
	@Bean
	public FilterRegistrationBean sessionFilterRegistration() {
		System.out.println("===================注册sessionFilter==================");
	    FilterRegistrationBean registration = new FilterRegistrationBean();
	    registration.setFilter(sessionFilter());
	    registration.setAsyncSupported(false);
	    registration.setName("asessionFilter");
	    registration.addUrlPatterns("/*");
	    registration.setMatchAfter(true);
	    registration.setOrder(1);
	    return registration;
	} 
	
	@Bean
	public FilterRegistrationBean myFilterRegistration() {
		System.out.println("===================注册myFilter==================");
		FilterRegistrationBean registration = new FilterRegistrationBean();
		registration.setFilter(myFilter());
		registration.setAsyncSupported(false);
		registration.setName("myFilter");
		registration.addUrlPatterns("/hello");
		registration.setOrder(2);
		registration.setMatchAfter(true);
		return registration;
	} 
	
	@Bean
	public Filter sessionFilter() {
		return new SessionFilter();
	}
	
	@Bean
	public Filter myFilter() {
		return new MyFilter();
	}
}